package com.tool.mysql.JDBCMysql;

import java.sql.*;

/**
 * @author 酒徒
 * @Version 1.0
 * @data 2025/4/15 10:34
 */
public class JDBConnection {
    public static void main(String[] args) {
        String url = "jdbc:mysql://localhost:3306/test";
        String username = "root";
        String password = "root";
        try {
            Connection connection = DriverManager.getConnection(url, username, password);
            if (connection != null) {
                System.out.println("连接成功！");

                String sql = "SELECT id FROM t_user";
                PreparedStatement preparedStatement = connection.prepareStatement(sql);
                ResultSet resultSet = preparedStatement.executeQuery();
                while (resultSet.next()) {
                    int id = resultSet.getInt("id");
                    System.out.println(id);
                }
            }

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }
}
